//
//  HomeDetailController.swift
//  maosheng
//
//  Created by lxl on 2019/8/20.
//

import UIKit

class HomeDetailController: RootViewController {
    var blogId : String?
    let detailView = HomeDetailView()
    let bottmView = BottomCommentView()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        addTopDetailView()
        getTheBlogDetailInfo()
    }
    func addTopDetailView(){
        
        view.addSubview(bottmView)
        bottmView.snp.makeConstraints { (make) in
            make.left.right.equalTo(0)
            make.height.equalTo(45)
            make.bottom.equalTo(-kBottomSafeHeight)
        }
        bottmView.blogId = self.blogId
        bottmView.refreshCommentInfo = {[weak self] (tag) in
            self?.getTheDetailCommentList()
        }
        
        
        view.addSubview(detailView)
        detailView.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(0)
            make.bottom.equalTo(bottmView.snp.top)
        }
        detailView.blogId = self.blogId
        getTheDetailCommentList()
    }
    func getTheDetailCommentList() {
        detailView.getTheDetailCommentList(isHeader: true)

    }
    func getTheBlogDetailInfo() -> Void {
        if self.blogId == nil {
            return
        }
        SDataCenter.shared.SGetJsonDataWithUrl(str_url: "api/services/app/Blog/GetBlogAsync", params: ["id" : self.blogId!]) { [weak self] (responseData, isSuccess) in
            
            if isSuccess && responseData is [String : Any]{
                if let model = HomeDetialModel.deserialize(from: responseData as? [String : Any]){
                        self?.detailView.setTheDetailInfo(model: model)
                        self?.bottmView.setTheCollectOrLikeState(model: model)
                }
                
            }else{
                
                
            }
        }
    }
}
